package com.wtwd.device.controller;

import com.alibaba.fastjson.JSONArray;
import com.wtwd.device.annotation.LightUpMedal;
import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.dto.SportRecord;
import com.wtwd.device.model.entity.*;
import com.wtwd.device.model.vo.RespEntity;
import com.wtwd.device.model.vo.ResultVO;
import com.wtwd.device.service.*;
import com.wtwd.device.util.AuditLogUtils;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author mjy
 * @date 2021/08/31
 * @description
 */
@Api(tags = "健康管理")
@RequestMapping("/app-health")
@RestController
public class AppHealthController {

    private static final Logger logger = LoggerFactory.getLogger(AppHealthController.class);

    @Value("${file.path}")
    private String filePath;

    @Value("${file.http}")
    private String fileHttp;

    @Value("${sport.location.file}")
    private String sportLocationFile;

    @Resource
    private StepService stepService;

    @Autowired
    private AppSportRecordService appSportRecordService;

    @Autowired
    private HeartRateService heartRateService;

    @Autowired
    private SleepRecordService sleepRecordService;

    @Autowired
    private BloodPressureRecordService bloodPressureRecordService;

    @Autowired
    private BloodOxygenRecordService bloodOxygenRecordService;

    @Autowired
    private BloodSugarRecordService bloodSugarRecordService;

    @Autowired
    private TempRecordService tempRecordService;


    @ApiOperation(value = "保存步数")
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @LightUpMedal(medalType = 1)
    @PostMapping("/stepInfo")
    public ResultVO saveStepInfo(@RequestBody List<SportRecord> sportRecords) {
        for (SportRecord sportRecord : sportRecords) {
            Step step = SportRecord.toStep(sportRecord);
            stepService.save(step);
        }
        return ResultVO.success();
    }

    @ApiOperation(value = "获取某天步数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "date", value = "日期,2021-08-31", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/dayStepInfo")
    public ResultVO<SportRecord> getDayStepInfo(@RequestParam Long deviceId, @RequestParam String date) {
        Step step = stepService.getByDeviceAndDate(deviceId, date);
        return ResultVO.success(SportRecord.toThis(step));
    }


    @ApiOperation(value = "获取一段时间步数信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "startDate", value = "开始日期,2021-08-31", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endDate", value = "结束日期,2021-09-01", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/daysStepInfo")
    public ResultVO<List<SportRecord>> getDaysStepInfo(@RequestParam Long deviceId, @RequestParam String startDate, @RequestParam String endDate) {
        List<Step> steps = stepService.listByDeviceAndDate(deviceId, startDate, endDate);
        int size = steps.size();
        ArrayList<SportRecord> sportRecords = new ArrayList<>(size);
        steps.forEach(item -> {
            sportRecords.add(SportRecord.toThis(item));
        });
        return ResultVO.success(sportRecords);
    }

    @ApiOperation(value = "获取某月步数信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "month", value = "月份,2021-08", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/monthStepInfo")
    public ResultVO<List<SportRecord>> getMonthStepInfo(@RequestParam Long deviceId, @RequestParam String month) {
        List<Step> steps = stepService.listByDeviceAndMonth(deviceId, month);
        int size = steps.size();
        ArrayList<SportRecord> sportRecords = new ArrayList<>(size);
        steps.forEach(item -> {
            sportRecords.add(SportRecord.toThis(item));
        });
        return ResultVO.success(sportRecords);
    }

    /**
     * 获取设备绑定的运动记录列表(需要统计总数，不做分页)
     *
     * @param deviceId
     * @return
     */
    @ApiOperation(value = "获取设备绑定的运动记录列表", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
    })
    @GetMapping("/getSportRecordList/{deviceId}")
    public RespEntity<List<SportModeInfo>> getSportRecordList(@PathVariable("deviceId") Long deviceId) {
        logger.info("getSportRecordList param" + deviceId);
        return appSportRecordService.getSportRecordListByDeviceId(deviceId);
    }


    /**
     * 添加设备绑定的运动记录列表
     *
     * @param sportModeInfo
     * @return
     */
    @LightUpMedal(medalType = 0)
    @ApiOperation(value = "添加设备绑定的运动记录", notes = "")
    @PostMapping("/addSportRecord")
    public RespEntity addSportRecord(@RequestBody SportModeInfo sportModeInfo) {
        logger.info("addSportRecord param" + sportModeInfo.toString());
        if (sportModeInfo.getDeviceId() == null || sportModeInfo.getSportType() == null || sportModeInfo.getDistance() == null
                || sportModeInfo.getAvgHeartRate() == null || sportModeInfo.getMaxHeartRate() == null
                || sportModeInfo.getTime() == null || sportModeInfo.getStartTime() == null || sportModeInfo.getEndTime() == null) {
            return new RespEntity(RespCode.PARAMS_ERROR);
        }
        RespEntity respEntity = appSportRecordService.addSportRecord(sportModeInfo);
        if (respEntity.getCode() == RespCode.SUCCESS.getCode()) {//如果成功添加运动数据，则根据运行类型,修改注解medalType的值
            Method method = null;
            try {
                method = AppHealthController.class.getMethod("addSportRecord", SportModeInfo.class);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
            Integer sportType = sportModeInfo.getSportType();
            //跑步类型集合
            ArrayList<Integer> runList = new ArrayList<>();
            runList.add(3);
            runList.add(4);
            runList.add(28);
            //骑行
            ArrayList<Integer> ridingList = new ArrayList<>();
            ridingList.add(1);
            ridingList.add(2);
            if (runList.stream().filter(e -> e.equals(sportType)).findAny().isPresent()) {
                AuditLogUtils.modifyAnnotation(method, 2);
            } else if (ridingList.stream().filter(e -> e.equals(sportType)).findAny().isPresent()) {
                AuditLogUtils.modifyAnnotation(method, 3);
            }
        }
        return respEntity;
    }

    /**
     * 获取设备最后一次记录的运动信息
     *
     * @param deviceId
     * @return
     */
    @ApiOperation(value = "获取设备最后一次记录的运动信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
    })
    @GetMapping("/getLastSportRecord/{deviceId}")
    public RespEntity<SportModeInfo> getLastSportRecord(@PathVariable("deviceId") Long deviceId) {
        logger.info("getLastSportRecord param" + deviceId);
        return appSportRecordService.getLastSportRecordByDeviceId(deviceId);
    }

    /**
     * 获取某一天的心率
     *
     * @param deviceId
     * @param day
     * @return
     */
    @ApiOperation(value = "获取某一天的心率")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "day", value = "日期", required = true, dataType = "String")
    })
    @GetMapping("/getDayHeartRate")
    public RespEntity<HeartRateRecord> getDayHeartRate(@RequestParam("deviceId") Long deviceId, @RequestParam("day") String day) {
        logger.info("getDayHeartRateList deviceId={},day={} ", deviceId, day);
        HeartRateRecord heartRateRecord = heartRateService.getHeartRateByDeviceIdAndTime(deviceId, day);
        if (heartRateRecord != null) {
            if (heartRateRecord.getHeartRateInfo() != null) {
                List<HeartRateInfo> heartRateInfos = JSONArray.parseArray(heartRateRecord.getHeartRateInfo(), HeartRateInfo.class);
                heartRateRecord.setListHeartRate(heartRateInfos);
            }
        }
        return new RespEntity<>(RespCode.SUCCESS, heartRateRecord);
    }


    /**
     * 根据起始时间获取该设备所记录的心率(起始时间以天为单位)
     *
     * @param deviceId
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "根据起始时间获取该设备所记录的心率")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "startTime", value = "开始日期,2021-08-31", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endTime", value = "结束日期,2021-09-01", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getDaysHeartRateList")
    public RespEntity<List<HeartRateRecord>> getDaysHeartRateList(@RequestParam("deviceId") Integer deviceId, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        logger.info("getDaysLastSportRecord param" + deviceId, startTime, endTime);
        return heartRateService.getDaysHeartRateList(deviceId, startTime, endTime);
    }

    /**
     * 根据月份获取该月份的心率记录
     *
     * @param deviceId
     * @param month
     * @return
     */
    @ApiOperation(value = "获取某月心率记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "month", value = "月份,2021-08", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getMonthHeartRateList")
    public RespEntity<List<HeartRateRecord>> getMonthHeartRateList(@RequestParam("deviceId") Integer deviceId, @RequestParam("month") String month) {
        logger.info("getMonthHeartRateList param" + deviceId, month);
        return heartRateService.getMonthHeartRateList(deviceId, month);
    }

    /**
     * 心率记录上传(一天上传一次)
     *
     * @param heartRateRecord
     * @return
     */
    @ApiOperation(value = "心率记录上传", notes = "一天记录的记录只能上传一次")
    @PostMapping("/addHeartRate")
    public RespEntity addHeartRate(@RequestBody HeartRateRecord heartRateRecord) {
        logger.info("addHeartRate param" + heartRateRecord.toString());
        return heartRateService.addHeartRate(heartRateRecord);
    }

    /**
     * 查找某一天睡眠记录
     */
    @ApiOperation(value = "查找某一天睡眠记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "day", value = "日期", required = true, dataType = "String")
    })
    @GetMapping("/getDaySleepRecord")
    public RespEntity<SleepRecord> getDaySleepRecord(@RequestParam("deviceId") Long deviceId, @RequestParam("day") String day) {
        logger.info("getDaySleepRecord deviceId={},day={} ", deviceId, day);
        SleepRecord sleepRecord = sleepRecordService.getSleepRecordByDeviceIdAndTime(deviceId, day);
        if (sleepRecord != null) {
            List<SleepInfo> sleepInfos = JSONArray.parseArray(sleepRecord.getSleepInfo(), SleepInfo.class);
            sleepRecord.setSleepInfoList(sleepInfos);
        }
        return new RespEntity<>(RespCode.SUCCESS, sleepRecord);
    }


    /**
     * 通过起始时间查找睡眠记录
     *
     * @param deviceId
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "通过起始时间查找睡眠记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "startTime", value = "开始日期,2021-08-31", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endTime", value = "结束日期,2021-09-01", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getDaysSleepRecord")
    public RespEntity<List<SleepRecord>> getDaysSleepRecord(@RequestParam("deviceId") Long deviceId, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        logger.info("getDaysSleepRecord param" + deviceId, startTime, endTime);
        return sleepRecordService.getDaysSleepRecord(deviceId, startTime, endTime);
    }


    /**
     * 通过月份查找睡眠记录
     *
     * @param deviceId
     * @param month
     * @return
     */
    @ApiOperation(value = "通过月份查找睡眠记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "month", value = "月份,2021-08", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getMonthSleepRecord")
    public RespEntity<List<SleepRecord>> getMonthSleepRecord(@RequestParam("deviceId") Long deviceId, @RequestParam("month") String month) {
        logger.info("getMonthSleepRecord param" + deviceId, month);
        return sleepRecordService.getMonthSleepRecord(deviceId, month);
    }

    /**
     * 添加睡眠记录，已日为单位记录，每天只会有一条记录
     *
     * @param sleepRecord
     * @return
     */
    @ApiOperation(value = "添加睡眠记录", notes = "已日为单位记录，每天只会有一条记录")
    @PostMapping("/addSleepRecord")
    public RespEntity addSleepRecord(@RequestBody SleepRecord sleepRecord) {
        logger.info("addSleepRecord param" + sleepRecord);
        return sleepRecordService.addSleepRecord(sleepRecord);
    }

    /**
     * 查找某一天血压
     *
     * @param deviceId
     * @param day
     * @return
     */
    @ApiOperation(value = "查找某一天血压")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "day", value = "日期", required = true, dataType = "String")
    })
    @GetMapping("/getDayBloodPressureRecord")
    public RespEntity<BloodPressureRecord> getDayBloodPressureRecord(@RequestParam("deviceId") Long deviceId, @RequestParam("day") String day) {
        logger.info("getDayBloodPressureRecord deviceId={},day={} ", deviceId, day);
        BloodPressureRecord bloodPressureRecord = bloodPressureRecordService.getBloodPressureRecordByDeviceIdAndTime(deviceId, day);
        if (bloodPressureRecord != null && StringUtils.isNotBlank(bloodPressureRecord.getBloodPressureInfo())) {
            bloodPressureRecord.setBloodPressureInfoList(JSONArray.parseArray(bloodPressureRecord.getBloodPressureInfo(), BloodPressureInfo.class));
        }
        return new RespEntity(RespCode.SUCCESS, bloodPressureRecord);
    }


    /**
     * 通过起始时间查找血压
     *
     * @param deviceId
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "通过起始时间查找血压")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "startTime", value = "开始日期,2021-08-31", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endTime", value = "结束日期,2021-09-01", required = true, dataType = "String")
    })
    @GetMapping("/getDaysBloodPressureRecordList")
    public RespEntity<List<BloodPressureRecord>> getBloodPressureRecordList(@RequestParam("deviceId") Long deviceId, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        logger.info("getBloodPressureRecordList param" + deviceId, startTime, endTime);
        return bloodPressureRecordService.getDaysBloodPressureRecordList(deviceId, startTime, endTime);
    }

    /**
     * 通过月份查找血压
     *
     * @param deviceId
     * @param month
     * @return
     */
    @ApiOperation(value = "通过月份查找血压")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "month", value = "月份,2021-08", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getMonthBloodPressureRecordList")
    public RespEntity<List<BloodPressureRecord>> getMonthBloodPressureRecordList(@RequestParam("deviceId") Long deviceId, @RequestParam("month") String month) {
        logger.info("getMonthBloodPressureRecordList param" + deviceId, month);
        return bloodPressureRecordService.getMonthBloodPressureRecordList(deviceId, month);
    }

    /**
     * 上传血压,已日为单位记录，每天只会有一条记录
     *
     * @param bloodPressureRecord
     * @return
     */
    @ApiOperation(value = "上传血压", notes = "已日为单位记录，每天只会有一条记录")
    @PostMapping("/addBloodPressureRecord")
    public RespEntity addBloodPressureRecord(@RequestBody BloodPressureRecord bloodPressureRecord) {
        logger.info("addBloodPressureRecord param" + bloodPressureRecord);
        return bloodPressureRecordService.addBloodPressureRecord(bloodPressureRecord);
    }

    /**
     * 查找某一天血氧数据
     */

    @ApiOperation(value = "查找某一天血氧数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "day", value = "日期", required = true, dataType = "String")
    })
    @GetMapping("/getDayBloodOxygenRecord")
    public RespEntity getDayBloodOxygenRecord(@RequestParam("deviceId") Long deviceId, @RequestParam("day") String day) {
        logger.info("getDayBloodOxygenRecord deviceId={},day={} ", deviceId, day);
        BloodOxygenRecord bloodOxygenRecord = bloodOxygenRecordService.getBloodOxygenRecordByDeviceIdAndTime(deviceId, day);
        if (bloodOxygenRecord != null && StringUtils.isNotBlank(bloodOxygenRecord.getBloodOxygenInfo())) {
            bloodOxygenRecord.setListBloodOxygen(JSONArray.parseArray(bloodOxygenRecord.getBloodOxygenInfo(), BloodOxygenInfo.class));
        }
        return new RespEntity(RespCode.SUCCESS, bloodOxygenRecord);
    }


    /**
     * 通过起始时间查找血氧
     *
     * @param deviceId
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "通过起始时间查找血氧")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "startTime", value = "开始日期,2021-08-31", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endTime", value = "结束日期,2021-09-01", required = true, dataType = "String")
    })
    @GetMapping("/getDaysBloodOxygenRecordList")
    public RespEntity<List<BloodOxygenRecord>> getDayBloodOxygenRecordList(@RequestParam("deviceId") Long deviceId, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        logger.info("getDaysBloodOxygenRecordList param" + deviceId, startTime, endTime);
        return bloodOxygenRecordService.getDaysBloodOxygenRecordList(deviceId, startTime, endTime);
    }


    /**
     * 通过月份查找血氧
     *
     * @param deviceId
     * @param month
     * @return
     */
    @ApiOperation(value = "通过月份查找血氧")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "month", value = "月份,2021-08", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getMonthBloodOxygenRecordList")
    public RespEntity<List<BloodOxygenRecord>> getMonthBloodOxygenRecordList(@RequestParam("deviceId") Long deviceId, @RequestParam("month") String month) {
        logger.info("getMonthBloodOxygenRecordList param" + deviceId, month);
        return bloodOxygenRecordService.getMonthBloodOxygenRecordList(deviceId, month);
    }


    /**
     * 上传血氧,已日为单位记录，每天只会有一条记录
     *
     * @param bloodOxygenRecord
     * @return
     */
    @ApiOperation(value = "上传血氧记录", notes = "已日为单位记录，每天只会有一条记录")
    @PostMapping("/addBloodOxygenRecord")
    public RespEntity addBloodOxygenRecord(@RequestBody BloodOxygenRecord bloodOxygenRecord) {
        logger.info("addBloodOxygenRecord param" + bloodOxygenRecord.toString());
        return bloodOxygenRecordService.addBloodOxygenRecord(bloodOxygenRecord);
    }


    /**
     * 查找某一天血糖数据
     *
     * @param deviceId
     * @param day
     * @return
     */
    @ApiOperation(value = "查找某一天血糖数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "day", value = "日期", required = true, dataType = "String")
    })
    @GetMapping("/getDayBloodSugarRecordList")
    public RespEntity getDayBloodSugarRecordList(@RequestParam("deviceId") Long deviceId, @RequestParam("day") String day) {
        logger.info("getDayBloodSugarRecordList deviceId={},day={} ", deviceId, day);
        BloodSugarRecord bloodSugarRecord = bloodSugarRecordService.getDayBloodSugarRecord(deviceId, day);
        if (bloodSugarRecord != null && StringUtils.isNotBlank(bloodSugarRecord.getBloodSugarInfo())) {
            bloodSugarRecord.setListBloodSugarRecord(JSONArray.parseArray(bloodSugarRecord.getBloodSugarInfo(), BloodSugarInfo.class));
        }
        return new RespEntity(RespCode.SUCCESS, bloodSugarRecord);
    }


    /**
     * 通过起始时间查找血糖
     *
     * @param deviceId
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "通过起始时间查找血糖")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "startTime", value = "开始日期,2021-08-31", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endTime", value = "结束日期,2021-09-01", required = true, dataType = "String")
    })
    @GetMapping("/getDaysBloodSugarRecordList")
    public RespEntity<List<BloodSugarRecord>> getDaysBloodSugarRecordList(@RequestParam("deviceId") Long deviceId, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        logger.info("getDaysBloodSugarRecordList param" + deviceId, startTime, endTime);
        return bloodSugarRecordService.getDaysBloodSugarRecordList(deviceId, startTime, endTime);
    }

    /**
     * @param deviceId
     * @param month
     * @return
     */
    @ApiOperation(value = "通过月份查找血糖")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "month", value = "月份,2021-08", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getMonthBloodSugarRecordList")
    public RespEntity<List<BloodSugarRecord>> getMonthBloodSugarRecordList(@RequestParam("deviceId") Long deviceId, @RequestParam("month") String month) {
        logger.info("getDaysBloodSugarRecordList param" + deviceId, month);
        return bloodSugarRecordService.getMonthBloodSugarRecordList(deviceId, month);
    }

    /**
     * 上传血糖,已日为单位记录，每天只会有一条记录
     *
     * @param bloodSugarRecord
     * @return
     */
    @ApiOperation(value = "上传血糖记录", notes = "已日为单位记录，每天只会有一条记录")
    @PostMapping("/addBloodSugarRecord")
    public RespEntity addBloodSugarRecord(@RequestBody BloodSugarRecord bloodSugarRecord) {
        logger.info("addBloodSugarRecord param" + bloodSugarRecord.toString());
        return bloodSugarRecordService.addBloodSugarRecord(bloodSugarRecord);
    }

    /**
     * 通过起始时间查找体温
     *
     * @param deviceId
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "通过起始时间查找体温")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "startTime", value = "开始日期,2021-08-31", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endTime", value = "结束日期,2021-09-01", required = true, dataType = "String")
    })
    @GetMapping("/getDaysTempRecordList")
    public RespEntity<List<TempRecord>> getDaysTempRecordList(@RequestParam("deviceId") Long deviceId, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        logger.info("getDaysBloodSugarRecordList param" + deviceId, startTime, endTime);
        return tempRecordService.getDaysTempRecordList(deviceId, startTime, endTime);
    }


    /**
     *
     */


    /**
     * 通过起始时间查找体温
     *
     * @param deviceId
     * @param month
     * @return
     */
    @ApiOperation(value = "通过月份查找体温")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "month", value = "月份,2021-08", required = true, dataType = "String")
    })
    @GetMapping("/getMonthTempRecordList")
    public RespEntity<List<TempRecord>> getMonthTempRecordList(@RequestParam("deviceId") Long deviceId, @RequestParam("month") String month) {
        logger.info("getMonthTempRecordList param" + deviceId, month);
        return tempRecordService.getMonthTempRecordList(deviceId, month);
    }


    /**
     * 上传温度,已日为单位记录，每天只会有一条记录
     *
     * @param tempRecord
     * @return
     */
    @ApiOperation(value = "上传温度", notes = "已日为单位记录，每天只会有一条记录")
    @PostMapping("/addTempRecord")
    public RespEntity addTempRecord(@RequestBody TempRecord tempRecord) {
        logger.info("addTempRecord param" + tempRecord.toString());
        return tempRecordService.addTempRecord(tempRecord);
    }


    /**
     * 定位点的文件上传
     */
    @ApiOperation(value = "定位点的文件上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "定位点的文件上传", required = true, dataTypeClass = MultipartFile.class)
    })
    @PostMapping("/uploadLocationFile")
    public RespEntity uploadLocationFile(@RequestParam MultipartFile file, @RequestParam String time) {
        logger.info("/uploadLocationFile");
        time = time.trim();
        String path = filePath.concat(sportLocationFile.concat(time + "/"));
        File saveFile = new File(path);
        if (!saveFile.exists()) {
            //文件不存在则创建一个
            saveFile.mkdir();
        }
        String originalFilename = file.getOriginalFilename();
        String fileName = UUID.randomUUID().toString().concat(originalFilename);
        File dest = new File(path.concat(fileName));
        try {
            file.transferTo(dest);
        } catch (IOException e) {
            e.printStackTrace();
            return new RespEntity(RespCode.FAIL);
        }
        //此处直接返回拼接好的图片地址--解决动态创建时间文件导致图片拼接的问题
        return new RespEntity(RespCode.SUCCESS, fileHttp.concat(sportLocationFile.concat(time.concat("/" + fileName))));
    }

}
